import Mock from 'mockjs';
import type { MockMethod } from 'vite-plugin-mock';

export default [
  {
    url: '/api/post',
    method: 'post',
    timeout: 2000,
    response: {
      code: 0,
      data: {
        name: 'vben',
      },
    },
  },
  // UEditorPlus 编辑器接口 - 配置接口
  {
    url: '/api/editor/server',
    method: 'get',
    timeout: 1000,
    response: ({ query }: { query: Record<string, string> }) => {
      const { action } = query;

      // 配置接口
      if (action === 'config') {
        return {
          code: 200,
          data: {
            // 图片上传配置
            imageActionName: 'image',
            imageFieldName: 'file',
            imageMaxSize: 5 * 1024 * 1024,
            imageAllowFiles: ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'],
            imageCompressEnable: true,
            imageCompressBorder: 1600,
            imageInsertAlign: 'none',
            imageUrlPrefix: '',

            // 视频上传配置
            videoActionName: 'video',
            videoFieldName: 'file',
            videoMaxSize: 100 * 1024 * 1024,
            videoAllowFiles: ['.mp4', '.avi', '.mov', '.wmv', '.flv', '.webm'],
            videoUrlPrefix: '',

            // 文件上传配置
            fileActionName: 'file',
            fileFieldName: 'file',
            fileMaxSize: 50 * 1024 * 1024,
            fileAllowFiles: ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf', '.txt', '.zip', '.rar'],
            fileUrlPrefix: '',

            // 涂鸦配置
            scrawlActionName: 'scrawl',
            scrawlFieldName: 'file',
            scrawlMaxSize: 2 * 1024 * 1024,
            scrawlUrlPrefix: '',

            // 截图配置
            snapscreenActionName: 'snapscreen',
            snapscreenUrlPrefix: '',

            // 抓取远程图片配置
            catcherLocalDomain: ['127.0.0.1', 'localhost'],
            catcherActionName: 'catch',
            catcherFieldName: 'source',
            catcherUrlPrefix: '',
            catcherMaxSize: 5 * 1024 * 1024,
            catcherAllowFiles: ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'],

            // 视频管理配置
            videoManagerActionName: 'listvideo',
            videoManagerListSize: 20,
            videoManagerUrlPrefix: '',
            videoManagerAllowFiles: [
              '.flv',
              '.swf',
              '.mkv',
              '.avi',
              '.rm',
              '.rmvb',
              '.mpeg',
              '.mpg',
              '.ogg',
              '.ogv',
              '.mov',
              '.wmv',
              '.mp4',
              '.wav',
              '.mid',
              '.asf',
            ],

            // 图片管理配置
            imageManagerActionName: 'listimage',
            imageManagerListSize: 20,
            imageManagerUrlPrefix: '',
            imageManagerAllowFiles: ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp'],

            // 文件管理配置
            fileManagerActionName: 'listfile',
            fileManagerListSize: 20,
            fileManagerUrlPrefix: '',
            fileManagerAllowFiles: ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf', '.txt', '.zip', '.rar'],
          },
        };
      }

      return {
        code: 404,
        message: '接口不存在',
      };
    },
  },
  // UEditorPlus 编辑器接口 - 图片上传
  {
    url: '/api/editor/server',
    method: 'post',
    timeout: 5000,
    response: ({ query, body }: { query: Record<string, string>; body: any }) => {
      const { action } = query;

      // 图片上传
      if (action === 'image') {
        return {
          code: 200,
          data: {
            state: 'SUCCESS',
            url: 'https://syeqq3lfd.hd-bkt.clouddn.com/mock-image-' + Date.now() + '.jpg',
            title: 'mock-image.jpg',
            original: 'mock-image.jpg',
            type: 'image/jpeg',
            size: 1024 * 1024,
          },
        };
      }

      // 视频上传
      if (action === 'video') {
        return {
          code: 200,
          data: {
            state: 'SUCCESS',
            url: 'https://syeqq3lfd.hd-bkt.clouddn.com/mock-video-' + Date.now() + '.mp4',
            title: 'mock-video.mp4',
            original: 'mock-video.mp4',
            type: 'video/mp4',
            size: 10 * 1024 * 1024,
          },
        };
      }

      // 文件上传
      if (action === 'file') {
        return {
          code: 200,
          data: {
            state: 'SUCCESS',
            url: 'https://syeqq3lfd.hd-bkt.clouddn.com/mock-file-' + Date.now() + '.pdf',
            title: 'mock-file.pdf',
            original: 'mock-file.pdf',
            type: 'application/pdf',
            size: 2 * 1024 * 1024,
          },
        };
      }

      // 抓取远程图片
      if (action === 'catch') {
        return {
          code: 200,
          data: {
            state: 'SUCCESS',
            list: [
              {
                state: 'SUCCESS',
                source: 'https://syeqq3lfd.hd-bkt.clouddn.com/caught-image-' + Date.now() + '.jpg',
                url: 'https://syeqq3lfd.hd-bkt.clouddn.com/caught-image-' + Date.now() + '.jpg',
              },
            ],
          },
        };
      }

      // 图片管理列表
      if (action === 'listimage') {
        return {
          code: 200,
          data: {
            state: 'SUCCESS',
            list: [
              {
                url: 'https://syeqq3lfd.hd-bkt.clouddn.com/list-image-1.jpg',
                mtime: Date.now(),
              },
              {
                url: 'https://syeqq3lfd.hd-bkt.clouddn.com/list-image-2.jpg',
                mtime: Date.now() - 86400000,
              },
            ],
            start: 0,
            total: 2,
          },
        };
      }

      // 视频管理列表
      if (action === 'listvideo') {
        return {
          code: 200,
          data: {
            state: 'SUCCESS',
            list: [
              {
                url: 'https://syeqq3lfd.hd-bkt.clouddn.com/mock-video-1.mp4',
                mtime: Date.now(),
              },
            ],
            start: 0,
            total: 1,
          },
        };
      }

      // 文件管理列表
      if (action === 'listfile') {
        return {
          code: 200,
          data: {
            state: 'SUCCESS',
            list: [
              {
                url: 'https://syeqq3lfd.hd-bkt.clouddn.com/mock-file-1.pdf',
                mtime: Date.now(),
              },
            ],
            start: 0,
            total: 1,
          },
        };
      }

      return {
        code: 404,
        message: '接口不存在',
      };
    },
  },
  // 指南类别管理接口
  {
    url: '/api/manage/category/list',
    method: 'get',
    timeout: 1000,
    response: ({ query }: { query: Record<string, string> }) => {
      const { pageNum = 1, pageSize = 10 } = query;

      // 生成模拟数据
      const mockData = Mock.mock({
        [`records|${pageSize}`]: [
          {
            'id|+1': 1,
            name: '@ctitle(3, 8)',
            createTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
            updateTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
          },
        ],
        total: 25,
      });

      return {
        code: 0,
        message: 'success',
        data: {
          records: mockData.records,
          total: mockData.total,
        } as any,
      };
    },
  },
  {
    url: '/api/manage/category',
    method: 'post',
    timeout: 1000,
    response: ({ body }: { body: any }) => {
      return {
        code: 0,
        message: '新增成功',
        data: {
          id: Mock.mock('@id'),
          ...body,
          createTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
          updateTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
      };
    },
  },
  {
    url: '/api/manage/category',
    method: 'put',
    timeout: 1000,
    response: ({ body }: { body: any }) => {
      return {
        code: 0,
        message: '更新成功',
        data: {
          ...body,
          updateTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
      };
    },
  },
  {
    url: '/api/manage/category/:ids',
    method: 'delete',
    timeout: 1000,
    response: () => {
      return {
        code: 0,
        message: '删除成功',
        data: null as any,
      };
    },
  },
  {
    url: '/api/manage/category/:id',
    method: 'get',
    timeout: 1000,
    response: ({ query }: { query: Record<string, string> }) => {
      const { id } = query;

      return {
        code: 0,
        message: 'success',
        data: {
          id: parseInt(id),
          name: Mock.mock('@ctitle(3, 8)'),
          createTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
          updateTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
      };
    },
  },
  // 指南管理接口
  {
    url: '/api/manage/guide/list',
    method: 'get',
    timeout: 1000,
    response: ({ query }: { query: Record<string, string> }) => {
      const { pageNum = 1, pageSize = 10, title, categoryId, beginTime, endTime } = query;

      // 生成模拟数据
      const mockData = Mock.mock({
        [`records|${pageSize}`]: [
          {
            'id|+1': 1,
            title: '@ctitle(5, 15)',
            categoryName: '@pick(["骨科康复", "神经康复", "疼痛康复", "儿童康复", "产后康复", "心脏康复", "老年康复"])',
            content: '@cparagraph(3, 7)',
            publisher: '@cname',
            createTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
            updateTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
            'readNum|1-1000': 1,
            'likeNum|1-100': 1,
            'isRead|0-1': 0,
          },
        ],
        total: 50,
      });

      return {
        code: 0,
        message: 'success',
        data: {
          records: mockData.records,
          total: mockData.total,
        },
      };
    },
  },
  {
    url: '/api/manage/guide/:id',
    method: 'get',
    timeout: 1000,
    response: ({ query }: { query: Record<string, string> }) => {
      const { id } = query;

      return {
        code: 0,
        message: 'success',
        data: {
          id: parseInt(id),
          title: Mock.mock('@ctitle(5, 15)'),
          categoryId: Mock.mock('@integer(1, 7)'), // 添加分类ID字段
          categoryName: Mock.mock(
            '@pick(["骨科康复", "神经康复", "疼痛康复", "儿童康复", "产后康复", "心脏康复", "老年康复"])',
          ),
          content: Mock.mock('@cparagraph(5, 10)'),
          publisher: Mock.mock('@cname'),
          createTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
          updateTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
          readNum: Mock.mock('@integer(1, 1000)'),
          likeNum: Mock.mock('@integer(1, 100)'),
          isRead: Mock.mock('@pick([0, 1])'),
        } as any,
      };
    },
  },
  {
    url: '/api/manage/guide',
    method: 'post',
    timeout: 1000,
    response: ({ body }: { body: any }) => {
      return {
        code: 0,
        message: '新增成功',
        data: {
          id: Mock.mock('@id'),
          ...body,
          createTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
          updateTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
      };
    },
  },
  {
    url: '/api/manage/guide',
    method: 'put',
    timeout: 1000,
    response: ({ body }: { body: any }) => {
      return {
        code: 0,
        message: '更新成功',
        data: {
          ...body,
          updateTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
      };
    },
  },
  {
    url: '/api/manage/guide/:ids',
    method: 'delete',
    timeout: 1000,
    response: () => {
      return {
        code: 0,
        message: '删除成功',
        data: null as any,
      };
    },
  },
  {
    url: '/api/get-menu-list-i18n',
    method: 'get',
    timeout: 2000,
    response: {
      code: 0,
      data: {
        ...Mock.mock({
          list: [
            {
              path: '/guide',
              name: 'guide',
              component: 'LAYOUT',
              redirect: '/guide/index',
              meta: {
                title: {
                  zh_CN: '指南管理',
                  en_US: 'Guide Management',
                },
                icon: 'book',
              },
              children: [
                {
                  path: 'index',
                  name: 'GuideIndex',
                  component: '/guide/index',
                  meta: {
                    title: {
                      zh_CN: '指南管理',
                      en_US: 'Guide Management',
                    },
                  },
                },
                {
                  path: 'category',
                  name: 'GuideCategory',
                  component: '/guide/category',
                  meta: {
                    title: {
                      zh_CN: '指南类别',
                      en_US: 'Guide Category',
                    },
                  },
                },
                {
                  path: 'add',
                  name: 'GuideAdd',
                  component: '/guide/GuideAdd',
                  meta: {
                    title: {
                      zh_CN: '新增指南',
                      en_US: 'Add Guide',
                    },
                    hidden: true,
                  },
                },
                {
                  path: 'detail',
                  name: 'GuideDetail',
                  component: '/detail/GuideDetail',
                  meta: {
                    title: {
                      zh_CN: '指南详情',
                      en_US: 'Guide Detail',
                    },
                    hidden: true,
                  },
                },
              ],
            },
            {
              path: '/user',
              name: 'user',
              component: 'LAYOUT',
              redirect: '/user/index',
              meta: {
                title: {
                  zh_CN: '个人中心',
                  en_US: 'User Center',
                },
                icon: 'user-circle',
              },
              children: [
                {
                  path: 'index',
                  name: 'UserIndex',
                  component: '/user/index',
                  meta: {
                    title: {
                      zh_CN: '个人中心',
                      en_US: 'User Center',
                    },
                  },
                },
              ],
            },
          ],
        }),
      },
    },
  },
] as MockMethod[];
